﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using dhDataAcess.sysDAL;
using dhDataAcess.Model;
using dhDataAcess.dataAcess.sysDataSetTableAdapters;
using dhDataAcess.dataAcess;
using dhDataAcess.baseBLL;

namespace dhSystemBLL.basicData
{
  public class basListBLL
    {
        private basListTableAdapter  _basListAdapter = null;
        private basListTableAdapter  basListAdapter
        {
            get
            {
                if (_basListAdapter == null) _basListAdapter = new basListTableAdapter();
                return _basListAdapter;
            }
        }
        /// <summary>
        /// 查询基础信息表
        /// </summary>
        /// <returns></returns>

        public sysDataSet.basListDataTable  getbasListAll()
        {
            try
            {
                return basListAdapter.GetDatabasListAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 查询基础信息表
        /// </summary>
        /// <returns></returns>

        public sysDataSet.basListDataTable getbasListAll(string baseType,string basNum)
        {
            try
            {
                return basListAdapter.GetDatabasListBybasNum(baseType ,basNum );
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 根据项目编号查询表
        /// </summary>
        /// <param name="basNum"></param>
        /// <returns></returns>

        public sysDataSet.basListDataTable  getbasListAll(string basNum)
        {
            try
            {

                return basListAdapter.GetDatabasListByNum(basNum);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        public sysDataSet.basListDataTable getbasListByType(string typeName)
        {
            try
            {

                return basListAdapter.GetDataBybasListType(typeName);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }


       
      /// <summary>
      /// 基础信息插入
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
        public int basListInsert(basListModel  row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                basListDAL basList = new basListDAL(tn, conn);
                basList.basListInsert(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

        public int basListUpdate(basListModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                basListDAL basList = new basListDAL(tn, conn);
                basList.basListUpdate(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

        public int basListstretbasNumUpdate(string basNum,string basType)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                basListDAL basList = new basListDAL(tn, conn);
                basList.basListretbasNumUpdate ( basNum,basType);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="basNum"></param>
        /// <returns></returns>

        public int basListDel(string basNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                basListDAL basList = new basListDAL(tn, conn);
                basList.basListDel(basNum);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 根据项目编号返回项目名称
        /// </summary>
        /// <param name="basNum"></param>
        /// <returns></returns>

        public int basListRetName(string basNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                basListDAL basList = new basListDAL(tn, conn);
                basList.basListretbasNameI(basNum );
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
